home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 2
/
Gold Medal Software Volume 2 (Gold Medal) (1994).iso
/
os2
/
cenvi2.arj
/
WINTOOLS.LIB
< prev
next >
Wrap
Text File
|
1993-12-10
|
20KB
|
538 lines
// WinTools.lib - Functions for setting the state of of PM windows. This
// file may be #included into other Cmm source files, or
// you can cut and paste in the parts that you need.
//
// Note: Most of these routines require either a window
// handle or a window title. You can use either, but
// using a Window handle is a little quicker. Many of these
// utilities require that you include PMdll.lib.
//
//
//***** GetWindowHandle(): Get the handle for this window
// SYNTAX: int GetWindowHandle(int WindowHandle)
// int GetWindowHandle(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: Returns Window handle for a Windows whose partial title is
// WindowTitle. Comparison is case-insensitive. If WindowTitle
// is not found then returns 0 (NULL).
// NOTE: If WindowHandle is input, then this returns WindowHandle if
// WindowHandle is valid, else returns 0. WindowTitle is a partial
// and case-insensitive match and so "write" would match the
// window titled "Write - THESIS.WRI".
//
//
//***** GetFocusChild(): Get the handle for child that last had focus
// SYNTAX: int GetWindowHandle(int WindowHandle)
// int GetWindowHandle(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: Returns Window handle for a child of this window that now has
// focus or most recently had focus before this window was
// made inactive. NULL if not focus child.
// NOTE: If WindowHandle is input, then this returns WindowHandle if
// WindowHandle is valid, else returns 0. WindowTitle is a partial
// and case-insensitive match and so "write" would match the
// window titled "Write - THESIS.WRI".
//
//
//***** GetWindowTitle(): Get full Window Title
// SYNTAX: string GetWindowTitle(int WindowHandle)
// string GetWindowTitle(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: Returns Full title for this window, or NULL if window not
// found or title not found
//
//
//***** SetWindowTitle(): Set title for window
// SYNTAX: bool SetWindowTitle(int WindowHandle,string NewTitle)
// bool SetWindowTitle(string WindowTitle,string NewTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// NewTitle: New full title for this window
// RETURN: TRUE if successful, else FALSE if WindowSpec is invalid.
//
//
//***** IsWindow(): Is this a valid window title or handle
// SYNTAX: bool IsWindow(int WindowHandle)
// bool IsWindow(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: Returns non-zero if this window exists, else returns zero (FALSE)
//
//
//***** IsMinimized(): Is window minimized (Iconic)
// SYNTAX: bool IsMinimized(int WindowHandle)
// bool IsMinimized(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: non-zero if Window is minimized (iconic) else zero (FALSE)
// if not minimized or if WindowSpec is invalid
//
//
//***** IsMaximized(): Is window maximized
// SYNTAX: bool IsMinimized(int WindowHandle)
// bool IsMinimized(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: non-zero if Window is maximized else zero (FALSE) if not
// maximized or if WindowSpec is invalid
//
//
//***** IsVisible(): Is window visible
// SYNTAX: bool IsVisible(int WindowHandle)
// bool IsVisible(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: non-zero if Window is visible else zero (FALSE) if not
// visible or if WindowSpec is invalid. Visible means that
// the window exists on the screen even if it is covered by
// other windows
//
//
//***** IsEnabled(): Is window enabled for input
// SYNTAX: bool IsEnabled(int WindowHandle)
// bool IsEnabled(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: non-zero if Window is enabled for mouse and keyboard input,
// else zero (FALSE) if not enabled or if WindowSpec is invalid
//
//
//***** GetWindowRect(): Get current window coordinates
// SYNTAX: bool GetWindowRect(int WindowHandle,struct Rectangle)
// bool GetWindowRect(string WindowTitle,struct Rectangle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// Rectangle: receive structure of current window with following members
// .left - coordinate for left edge of window
// .right - coordinate for right edge of window
// .top - coordinate for top edge of window
// .bottom - coordinate for bottom edge of window
// RETURN: TRUE if WindowSpec is valid, else FALSE.
// MODIFY: Modifies Rectangle structure to current coordinates
//
//
//***** SetWindowRect(): Set current window coordinates
// SYNTAX: bool SetWindowRect(int WindowHandle,struct Rectangle)
// bool SetWindowRect(string WindowTitle,struct Rectangle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// Rectangle: new structurw of window with the same member elements as
// defined above in GetWindowRect()
// RETURN: TRUE if WindowSpec is valid, else FALSE.
//
//
//***** GetScreenSize(): Get width and height of the windows screen
// SYNTAX: void GetScreenSize(int Width,int Height);
// WHERE: Width: receive screen width
// Height: receive screen height
// MODIFY: Sets Width and Height to dimensions of screen
//
//
//***** GetSize(): Get current width and height of window
// SYNTAX: bool GetSize(int WindowHandle,int Width,int Height)
// bool GetSize(string WindowTitle,int Width,int Height)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// Width: receive current window width
// Height: receive current window height
// RETURN: TRUE if WindowSpec is valid, else FALSE.
// MODIFY: Sets Width and Height to current dimensions of window
//
//
//***** SetSize(): Get current width and height of window
// SYNTAX: bool GetSize(int WindowHandle,int Width,int Height)
// bool GetSize(string WindowTitle,int Width,int Height)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// Width: new window width
// Height: new window height
// RETURN: TRUE if WindowSpec is valid, else FALSE.
//
//
//***** GetPosition(): Get current column and row of window
// SYNTAX: bool GetPosition(int WindowHandle,int LeftCol,int BottomRow)
// bool GetPosition(string WindowTitle,int LeftCol,int BottomRow)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// LeftCol: receive current column coordinate of lower-left corner of window
// Height: receive current row coordinate of lower-left corner of window
// RETURN: TRUE if WindowSpec is valid, else FALSE.
// MODIFY: Sets LeftCol and BottomRow to current lower-left corner coordinates
//
//
//***** SetPosition(): Get current column and row of window
// SYNTAX: bool SetPosition(int WindowHandle,int LeftCol,int BottomRow)
// bool SetPosition(string WindowTitle,int LeftCol,int BottomRow)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// LeftCol: new column coordinate of lower-left corner of window
// Height: new row coordinate of lower-left corner of window
// RETURN: TRUE if WindowSpec is valid, else FALSE.
//
//
//***** ShowWindow(): Set the way the window is shown (or not shown)
// SYNTAX: bool ShowWindow(int WindowHandle,int ShowCommand)
// bool ShowWindow(string WindowTitle,int ShowCommand)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// ShowCommand: Any of the following values:
#define SW_HIDE 0 // Hide window; make NOT the active window
#define SW_MINIMIZE 6 // minimize window; make NOT the active window
#define SW_RESTORE 9 // activate and display this window; restore from minimized
// or maximized to original size and position before
// it was minimized or maximized
#define SW_RESTORENOACTIVE (-9) // Same as restore but active window remains active
#define SW_SHOW 5 // Activate this window in current size and position
#define SW_SHOWMAXIMIZED 3 // Activate this window and maximize
#define SW_SHOWMAXNOACTIVE (-3) // Display maximized; active window stays active
#define SW_SHOWMINIMIZED 2 // Activate this window and display as icon
#define SW_SHOWMINNOACTIVE 7 // Display as icon; active window stays active
#define SW_SHOWNA 8 // don't change window state or active window
#define SW_SHOWNOACTIVATE 4 // display in recent size and place; active window stays active
#define SW_SHOWNORMAL 1 // same as SW_RESTORE
//
//
//***** GetActiveWindow(): Get the active window
// SYNTAX: int GetActiveWindow()
// RETURN: Return window handle for currently active window
//
//
//***** SetActiveWindow(): Set the currently active window
// SYNTAX: bool SetActiveWindow(int WindowHandle)
// bool SetActiveWindow(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: TRUE if WindowSpec is valid, else FALSE.
//
//
//***** CloseWindow(): Send a CLOSE message to this window
// SYNTAX: bool CloseWindow(int WindowHandle)
// bool CloseWindow(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: TRUE if WindowSpec is valid, else FALSE.
//
//
//***** GetFocusChild(): Get the handle for child that last had focus
// SYNTAX: int GetFocusChild(int WindowHandle)
// int GetFocusChild(string WindowTitle)
// WHERE: WindowHandle: Integer identifier for this window
// WindowTitle: Partial text title of the window (case-insensitive)
// RETURN: Returns Window handle for a child of this window that now has
// focus or most recently had focus before this window was
// made inactive. NULL if not focus child.
//
//
//
//
// Initialization: make sure that PMdll.lib has been #included
if !defined(_PMDLL_LIB) {
printf("\n\aMust #include \"PMdll.lib\" before #include \"WinTools.lib\"\n");
abort();
}
#define _WINDTOOLS_LIB 1
#define HWND_DESKTOP 1
/*******************************************************************
********* END OF DESCRIPTION FOR WINSET.LIB *********
*******************************************************************/
GetWindowHandle(WindowSpec)
{
// Test if input is string (WindowTitle) or integer (WindowHandle)
if ( 0 == DataDimension(WindowSpec) ) {
// Input is WindowHandle. Verify that this handle is valid
#define ORD_WIN32ISWINDOW 772
if ( HWND_DESKTOP == WindowSpec
|| PMDynamicLink("PMWIN",ORD_WIN32ISWINDOW,BIT32,CDECL,PMInfo().hab,WindowSpec) )
return(WindowSpec);
} else {
// Input is WindowTitle, build list of titles and look for this one
_TitleLen = strlen(WindowSpec);
// Build list of all root window titles
if ( NULL != (_SwitchList = WinQuerySwitchList(PMInfo().hab)) ) {
// for each window, compare its title against Window
BLObSize(_buf,200);
for ( _i = GetArraySpan(_SwitchList); 0 <= _i; _i-- ) {
if ( 0 == WinQuerySwitchEntry(_SwitchList[_i],_SwEntry) ) {
if ( NULL != (_title = GetWindowTitle(_SwEntry.hwnd))
&& !memicmp(WindowSpec,_title,_TitleLen) )
return(_SwEntry.hwnd);
}
}
}
}
// if didn't return a handle above, then title was not found
return(0);
}
GetWindowTitle(WindowSpec)
{
if ( (_handle = GetWindowHandle(WindowSpec)) ) {
#define ORD_WIN32QUERYWINDOWTEXT 841
BLObSize(_buf,200);
if ( PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWTEXT,BIT32,CDECL,_handle,199,_buf) ) {
strcpy(_ret,_buf);
return(_ret);
}
}
return(NULL);
}
SetWindowTitle(WindowSpec,NewTitle)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
#define ORD_WIN32SETWINDOWTEXT 877
PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWTEXT,BIT32,CDECL,_handle,NewTitle);
return(TRUE);
}
IsWindow(WindowSpec)
{
return( GetWindowHandle(WindowSpec) );
}
#define SWP_SIZE 0x0001
#define SWP_MOVE 0x0002
#define SWP_ZORDER 0x0004
#define SWP_SHOW 0x0008
#define SWP_HIDE 0x0010
#define SWP_NOREDRAW 0x0020
#define SWP_NOADJUST 0x0040
#define SWP_ACTIVATE 0x0080
#define SWP_DEACTIVATE 0x0100
#define SWP_EXTSTATECHANGE 0x0200
#define SWP_MINIMIZE 0x0400
#define SWP_MAXIMIZE 0x0800
#define SWP_RESTORE 0x1000
#define SWP_FOCUSACTIVATE 0x2000
#define SWP_FOCUSDEACTIVATE 0x4000
QueryWinFlags(WindowSpec) // return WinPos flags for this window
{ // return 0 if no good
if ( (_handle = GetWindowHandle(WindowSpec)) ) {
#define SWP_BLOB_SIZE 9 * 4
BLObSize(_swp,SWP_BLOB_SIZE);
#define ORD_WIN32QUERYWINDOWPOS 837
if ( PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,_handle,_swp) )
return(BLObGet(_swp,0,UWORD32));
}
return(0);
}
IsMinimized(WindowSpec)
{
return( QueryWinFlags(WindowSpec) & SWP_MINIMIZE );
}
IsMaximized(WindowSpec)
{
return( QueryWinFlags(WindowSpec) & SWP_MAXIMIZE );
}
IsVisible(WindowSpec)
{
#define ORD_WIN32ISWINDOWVISIBLE 775
return( (_handle = GetWindowHandle(WindowSpec))
? PMDynamicLink("PMWIN",ORD_WIN32ISWINDOWVISIBLE,BIT32,CDECL,_handle)
: FALSE );
}
IsEnabled(WindowSpec)
{
#define ORD_WIN32ISWINDOWENABLED 773
return( (_handle = GetWindowHandle(WindowSpec))
? PMDynamicLink("PMWIN",ORD_WIN32ISWINDOWENABLED,BIT32,CDECL,_handle)
: FALSE );
}
SetWindowPos(Handle,BehindHandle,Column,Row,Width,Height,Flags)
{
#define ORD_WIN32SETWINDOWPOS 875
PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
Handle,BehindHandle,Column,Row,Width,Height,Flags);
}
GetWindowRect(WindowSpec,Rectangle)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
#define SWP_BLOB_SIZE 9 * 4
BLObSize(_swp,SWP_BLOB_SIZE);
#define ORD_WIN32QUERYWINDOWPOS 837
if ( !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,_handle,_swp) )
return(FALSE);
_height = BLObGet(_swp,4,SWORD32);
_width = BLObGet(_swp,8,SWORD32);
Rectangle.bottom = BLObGet(_swp,12,SWORD32);
Rectangle.left = BLObGet(_swp,16,SWORD32);
Rectangle.top = Rectangle.bottom + _height - 1;
Rectangle.right = Rectangle.left + _width - 1;
return(TRUE);
}
SetWindowRect(WindowSpec,Rectangle)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
SetWindowPos(_handle,0,Rectangle.left,Rectangle.bottom,
Rectangle.right - Rectangle.left + 1,
Rectangle.top - Rectangle.bottom + 1,
SWP_SIZE | SWP_MOVE | SWP_NOADJUST);
return(TRUE);
}
GetScreenSize(Width,Height)
{
GetSize(HWND_DESKTOP,Width,Height);
}
GetSize(WindowSpec,Width,Height)
{
if ( !GetWindowRect(WindowSpec,_rect) )
return(FALSE);
Width = _rect.right - _rect.left + 1;
Height = _rect.top - _rect.bottom + 1;
return(TRUE);
}
SetSize(WindowSpec,Width,Height)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
SetWindowPos(_handle,0,0,0,Width,Height,SWP_SIZE);
return(TRUE);
}
GetPosition(WindowSpec,LeftCol,BottomRow)
{
if ( !GetWindowRect(WindowSpec,_rect) )
return(FALSE);
LeftCol = _rect.left;
BottomRow = _rect.bottom;
return(TRUE);
}
SetPosition(WindowSpec,LeftCol,BottomRow)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
SetWindowPos(_handle,0,LeftCol,BottomRow,0,0,SWP_MOVE | SWP_NOADJUST);
return(TRUE);
}
ShowWindow(WindowSpec,CmdShow)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
_active = 0;
switch( CmdShow ) {
case SW_HIDE:
SetWindowPos(_handle,0,0,0,0,0,SWP_HIDE);
break;
case SW_SHOWNOACTIVATE:
_active = GetActiveWindow();
SetWindowPos(_handle,0,0,0,0,0,SWP_SHOW);
break;
case SW_MINIMIZE:
case SW_SHOWMINNOACTIVE:
SetWindowPos(_handle,0,0,0,0,0,SWP_MINIMIZE);
break;
case SW_SHOWMINIMIZED:
SetWindowPos(_handle,0,0,0,0,0,SWP_MINIMIZE | SWP_ACTIVATE);
break;
case SW_SHOWMAXNOACTIVE:
SetWindowPos(_handle,0,0,0,0,0,SWP_MAXIMIZE);
break;
case SW_SHOWMAXIMIZED:
SetWindowPos(_handle,0,0,0,0,0,SWP_MAXIMIZE | SWP_ACTIVATE);
break;
case SW_RESTORENOACTIVE:
SetWindowPos(_handle,0,0,0,0,0,SWP_RESTORE);
break;
case SW_RESTORE:
case SW_SHOWNORMAL:
SetWindowPos(_handle,0,0,0,0,0,SWP_RESTORE | SWP_ACTIVATE);
break;
case SW_SHOW:
SetActiveWindow(_handle);
break;
case SW_SHOWNA:
break;
default: return(FALSE);
}
if ( _active )
SetActiveWindow(_active);
return(TRUE);
}
GetActiveWindow()
{
#define ORD_WIN32QUERYACTIVEWINDOW 799
return PMDynamicLink("PMWIN",ORD_WIN32QUERYACTIVEWINDOW,BIT32,CDECL,HWND_DESKTOP);
}
SetActiveWindow(WindowSpec)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
SetWindowPos(_handle,0,0,0,0,0,SWP_ACTIVATE);
return(TRUE);
}
CloseWindow(WindowSpec)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
#define WM_CLOSE 0x0029
PostMessage(_handle,WM_CLOSE,0,0);
return(TRUE);
}
GetFocusChild(WindowSpec)
{
if ( !(_handle = GetWindowHandle(WindowSpec)) )
return(FALSE);
if ( _handle == GetActiveWindow() ) {
// This is currently the active window, so just get the focus window
#define ORD_WIN32QUERYFOCUS 817
return PMDynamicLink("PMWIN",ORD_WIN32QUERYFOCUS,BIT32,CDECL,HWND_DESKTOP);
} else {
// This window is not currently active, so get what the active window
// used to be.
#define QWL_HWNDFOCUSSAVE 0x0018
#define ORD_WIN32QUERYWINDOWULONG 843
return PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWULONG,BIT32,CDECL,
_handle,QWL_HWNDFOCUSSAVE);
}
}